﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

namespace EGuayas.Web
{
    public partial class EncryptWebConfig : pgBase
    {
        string provider = "RSAProtectedConfigurationProvider";
        string section = "appSettings";
       //“DataProtectionConfigurationProvider” ¬ “RSAProtectedConfigurationProvider” ¬ “DataProtectionConfigurationProvider” and use same code.
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnEncriptar_Click(object sender, DirectEventArgs e)
        {
            Configuration confg = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            ConfigurationSection configSect = confg.GetSection(section);
            if (configSect != null)
            {
                configSect.SectionInformation.ProtectSection(provider);
                confg.Save();
                txtComentario.Text = "ok";
            }
            this.btnOk.Disable();
            this.btnNoOk.Disable();
        }
        //
        protected void btnDesencriptar_Click(object sender, DirectEventArgs e)
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            ConfigurationSection configSect = config.GetSection(section);
            if (configSect.SectionInformation.IsProtected)
            {
                configSect.SectionInformation.UnprotectSection();
                config.Save();
                txtComentario.Text = "ok";
            }
            this.btnOk.Disable();
            this.btnNoOk.Disable();
        }
    }
}